#include<bits/stdc++.h>
using namespace std;
#define int long long 
typedef std::vector<int> v;
typedef pair<int, int> pii;
const int inf = 0x3f3f3f3f;
void slove()
{
	int a,k,p;cin>>a>>k>>p;
	int tmp1=a;int tmp2=k;
	int ret=1;
	while(k)
	{
	    if(k&1)ret*=a%p,ret%=p;//判断幂的二进制此位置是否有1,如果有1就乘上权值
	    a=a*a%p;//更新权值
	    k=k>>1;//更新幂
	}
	printf("%lld^%lld mod %lld=%lld\n",tmp1,tmp2,p,ret);
}

signed main()
{
	int t = 1;
	//cout << (3>>1 & 1) << endl;
	while (t--) {
		slove();
	}
	return 0;
}
